import pymysql
try:
    connect = pymysql.connect(host='127.0.0.1',
                              user='root',
                              password='root',
                              db='spider',
                              charset='utf8')
    cursor = connect.cursor()
    sql = "insert into teacherinfo(tno,tname) values(%s,%s)"
    val = [['1300434', '白云'], ['1300433', '黑土']]
    cursor.executemany(sql, val)
    connect.commit()
except Exception as e:
    connect.rollback()
    print(e)
finally:
    cursor.close()
    connect.close()

































